from cls.orm.mysql import Mysql


class Statistic(object):

    def __init__(self):
        self.db = Mysql()

    # level 为村，镇，县，市，省 , name为具体的村名，市名等
    def statTransfer(self, level, name):
        field = self.defineField(level)
        sql = ''
        if field != '':
            sql = 'select ' + field +',sum(shoudtrans) from statshouldvillage where ' + field + " ='" + name + "'" + " group by " + field
        res = self.db.exec(sql)
        print(res)
        exit(3)


    def transferred(self):
        pass

    def statTransfered(self):
        pass


    def defineField(self, level):
        field = ''
        if level == '村':
            field = 'village'
        if level == '镇':
            field = 'TOWN'
        if level == '县':
            field = 'county'
        if level == '市':
            field = 'city'
        return field



obj = Statistic()
obj.statTransfer("镇", '太阳镇')

